package ThreadPool.chapter2;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2022/12/20 21:31
 */
public class SynchronizedComparsion {

    static void test(Guard guard){
        List<CompletableFuture<Void>> collect = Stream.of(new Caller(guard), new Caller(guard), new Caller(guard), new Caller(guard))
                .map(CompletableFuture::runAsync).collect(Collectors.toList());
        collect.forEach(CompletableFuture::join);
        System.out.println(guard);
    }

    public static void main(String[] args) {
        // 同步方法
        test(new SynchronizedMethod());
        // 同步代码块
        test(new SynchronizedMethod2());
    }

}
